﻿@model IEnumerable<Hrm.Core.School>

@{
    ViewBag.Title = "同学管理";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<div id="page-header" class="clearfix">
    <div class="page-header">
        <h2>同学管理</h2>
        <span class="txt">可以增删查改同学信息</span>
    </div>
</div>
<div class="panel panel-default toggle panelMove panelClose panelRefresh">
    <!-- Start .panel -->
    <div class="panel-heading">
        <h4 class="panel-title">查询条件</h4>
    </div>
    <div class="panel-body pt0 pb0">
        <form class="form-horizontal group-border">
            <div class="form-group col-lg-4 col-md-6">
                <label class="col-lg-3 col-md-3 control-label" for="">学校</label>
                <div class="col-lg-9 col-md-9">
                    <select id="ddlSchoolId" class="fancy-select form-control">
                        <option value="">全部</option>
                        @foreach (var item in Model)
                        {
                            <option value="@item.Id">@item.Name</option>
                        }
                    </select>
                </div>
            </div>
            <div class="form-group col-lg-4 col-md-6">
                <label class="col-lg-3 col-md-3 control-label" for="">姓名</label>
                <div class="col-lg-9 col-md-9">
                    <input id="txtClassmateName" type="text" class="form-control" name="default">
                </div>
            </div>
            <div class="form-group col-lg-4 col-md-6">
                <label class="col-lg-3 col-md-3 control-label" for="">电话</label>
                <div class="col-lg-9 col-md-9">
                    <input id="txtPhone" type="text" class="form-control" name="default">
                </div>
            </div>
        </form>
    </div>
    <div class="panel-footer">
        <a id="btnAdd" class="btn btn-primary button-floatRight" data-href="@Url.Action("Create")">添加</a>
        <button id="btnReset" type="reset" class="btn btn-danger button-floatRight">重置</button>
        <button id="btnQuery" type="submit" class="btn btn-primary button-floatRight">查询</button>
    </div>
</div>

<table id="ClassMateTable" class="table table-striped table-bordered" cellspacing="0" width="100%">
    <thead>
        <tr>
            <td>姓名</td>
            <td>地址</td>
            <td>电话</td>
            <td>QQ</td>
            <td>微信</td>
            <td>公司</td>
            <td>描述</td>
            <td>操作</td>
        </tr>
    </thead>
</table>
<script>
    $(document).ready(function () {
        ClassMate.Search();

        $("#btnAdd").click(function () {
            ClassMate.Add(this);
        });

        $("#btnQuery").click(function () {
            ClassMate.Search();
        });

        $("#btnReset").click(function () {
            $("form").each(function () {
                this.reset();
            });
        });
    });

    var ClassMate = {
        Search: function () {
            $("#ClassMateTable").mainToolDataTable({
                "ajax": {
                    url: '@Url.Action("PageClassMates")',
                    type: 'POST',
                    data: { filter: { SchoolId: $("#ddlSchoolId").val(), Name: $("#txtClassmateName").val(), Phone: $("#txtPhone").val() } }
                },
                "columns": [
                    { "data": "Name" },
                    { "data": "Address" },
                    { "data": "Phone" },
                    { "data": "QQ" },
                    { "data": "WeChat" },
                    { "data": "Company" },
                    { "data": "Description" },
                    {
                        title: "操作",
                        orderable: false,
                        data: "Id",
                        style: "min-width:190px;",
                        render: function (data, type, row) {
                            return "<a href='javascript:void()' data-href='@Url.Action("Details")?id=" + data + "' onclick='ClassMate.Details(this);'>查看</a>&nbsp;&nbsp;<a href='javascript:void()' data-href='@Url.Action("Edit")?id=" + data + "' onclick='ClassMate.Edit(this);'>修改</a>&nbsp;&nbsp;<a href='javascript:void()' data-href='@Url.Action("Delete")?id=" + data + "' onclick='ClassMate.Delete(this);'>删除</a>";
                        }
                    }
                ]
            });
        },
        Add: function (e) {
            $.mainTool.ajaxModal($(e).attr("data-href"), "添加资源", function (result) {
                ClassMate.SubmitAdd();
            });
        },
        Edit: function (e) {
            $.mainTool.ajaxModal($(e).attr("data-href"), "编辑资源", function (result) {
                ClassMate.SubmitEdit();
            });
        },
        Details: function (e) {
            $.mainTool.ajaxViewModal($(e).attr("data-href"), "查看资源");
        },
        Delete: function (e) {
            $.mainTool.confirm("是否删除该资源？", function (result) {
                $.ajax({
                    type: 'post',
                    url: $(e).attr("data-href"),
                    dataType: "json",
                    success: function (data) {
                        ClassMate.Search();
                    },
                    error: function (e) {
                        alert(e.responseText);
                    }
                });
            });
        }
    };    
</script>